package com.jiexin.config;

import com.jiexin.common.ConfigDatasource;
import com.jiexin.dao.dsh.ConfigMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * @Author: Jay_Liu
 * @Description:  配置缓存类
 * @Date: Created in 21:19 2018/7/19
 * @Modified By:
 */
@Configuration
public class AppConfig {
    @Autowired
    private ConfigMapper configMapper;

    @Bean(value = "configDatasource")
    public ConfigDatasource configDatasource() {
        List<Map<String, Object>> maps = configMapper.findAllConfigurations();
        if (maps != null && maps.size() > 0) {
            Map<String,String> result = new HashMap<>();
            for (Map<String,Object> map : maps) {
                result.put((String) map.get("CONFIGNAME"), (String)map.get("CONFIGVALUE"));
            }
            return new ConfigDatasource(result);
        }
        return null;
    }

}
